<?php
//-------------------------------------------------------------------------------------------------------
    require_once($config['app_dir'] . '/includes/number.class.php');
    require_once($config['app_dir'] . '/includes/template.class.php');
    require_once($config['app_dir'] . '/classes/tracks.class.php');
    //---------------------------------------------------------------------------------------------------
    class objPerfServer {
            protected $_data = false;
            protected $_sql_querys = array();
            public $perfPeriod = array();
            public $userID;

        public function __construct( $perfYear, $perfMonth) {
            $this->_sqls();
            $this->Tpl = new objTemplate();
        	//$this->Tpl->caching = 2;
            $this->Tpl->cache_lifetime = 300;

            $this->perfPeriod[] = $perfYear;
            $this->perfPeriod[] = $perfMonth;
        }//constructor

        public function getMAPPerformance() {
          	$this->_data = objDataBase::GetInstance()->handler->GetAll($this->_sql_querys['map_perf'], $this->perfPeriod);
            return true;
        } //getMAPPerformance


        public function RenderMAP() {
            //$this->Tpl->cache_lifetime = 300;
            $this->Tpl->Assign('data', $this->_data);
            return $this->Tpl->Fetch('_PerformanceBlockItem.tpl');
        } //Render

        protected function _sqls() {
            $this->_sql_querys['rates'] =
                           "SELECT *, FROM_UNIXTIME((r.`Time`+?), '%Y-%m-%d %H:%i:%s') as RateTime ".
                           " FROM fa_rates r ".
                              "LEFT OUTER join fa_trades t ON (t.TradeID=r.TradeID ) ".
                           " ORDER BY r.SortIndex ";
            $this->_sql_querys['map_perf'] =
                           "SELECT m.MAPName, p.Result ".
                           " FROM fa_map m ".
                           "LEFT JOIN fa_map_performance p ON p.MAPID = m.ID ".
                           "WHERE p.Year=? && p.Month=?".
                           " ORDER BY m.ID DESC ";
        } //_sqls

    } //class objLastRateServer

    //---------------------------------------------------------------------------------------------------
    function showPerfSignals( $perfYear, $perfMonth ) {
        ob_start();
        //$PerfServer = new objPerfServer($perfYear, $perfMonth);
        if ($perfMonth<10) $perfMonth = "0$perfMonth";
        $dateKey = "$perfYear$perfMonth";

        $Response = new xajaxResponse();

        //if( !$trade && !$system ) {
            //$Response->addAssign('divTracks_HeaderPairs', 'style.display', 'none');
           // $Response->addAssign('hline', 'style.display', 'none');
        //} else {
            //$Response->addAssign('divTracks_HeaderPairs', 'style.display', 'inline');
            //$Response->addAssign('hline', 'style.display', 'inline');
        //}

        $ActionShow = new objActionTrackRecord_Show($Response);
        $ActionShow->trade = $trade;
        $ActionShow->system = $system;
        $ActionShow->flag_show_active = false;
        $ActionShow->flag_show_forecasts = false;
        $ActionShow->flag_effect = false;
        $ActionShow->isPerfTable = $dateKey;
        return $ActionShow->getResponse();






        //----------------------------------------------------------------------
        //$objResponse = new xajaxResponse();
        //$objResponse->addAssign("divPerfTable","innerHTML", $PerfServer->Render());
        //$objResponse->addAssign("divPerfTable","innerHTML", 'signals perf');
        //----------------------------------------------------------------------
        //$errors = ob_get_contents();
        //ob_end_clean();
        //return $objResponse;
    }//showLastRates

     function showPerfMaps( $perfYear, $perfMonth) {
        ob_start();
        $PerfServer = new objPerfServer($perfYear, $perfMonth);
        $PerfServer->getMAPPerformance();
        //----------------------------------------------------------------------
        $objResponse = new xajaxResponse();
        $objResponse->addAssign("divTracksMain","innerHTML", $PerfServer->RenderMap());
        //----------------------------------------------------------------------
        $errors = ob_get_contents();
        ob_end_clean();
        return $objResponse;
    }//showLastRates



    /*

    ob_start();
        $LastRateServer = new objPerfServer();
        $LastRateServer->userID = $userID;
        //----------------------------------------------------------------------
        $objResponse = new xajaxResponse();
        $objResponse->addAssign("divPerfTable","innerHTML", $LastRateServer->Render());
        //----------------------------------------------------------------------
        $errors = ob_get_contents();
        ob_end_clean();
    */


//-------------------------------------------------------------------------------------------------------
?>
